package logic

import (
	"ball/models/mysql"
	"context"
	"fmt"

	"ball/ballrpc/ballrpc"
	"ball/ballrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectLogic {
	return &PerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 完善信息
func (l *PerfectLogic) Perfect(in *ballrpc.PerfectRequest) (*ballrpc.PerfectResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User
	mysql.DB.Debug().Where("id=?", in.UserId).Find(&user)
	if user.ID == 0 {
		return nil, fmt.Errorf("用户不存在")
	}
	in.Image = user.Image
	in.Username = user.Username
	mysql.DB.Debug().Create(&user)
	return &ballrpc.PerfectResponse{
		Id: int64(user.ID),
	}, nil
}
